package com.itheima.service.impl;


import com.itheima.dao.AccountDao;
import com.itheima.service.AccountService;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus;
<<<<<<< Updated upstream
import org.springframework.transaction.support.DefaultTransactionDefinition;

import javax.sql.DataSource;
=======
import org.springframework.transaction.interceptor.DefaultTransactionAttribute;
import org.springframework.transaction.support.DefaultTransactionDefinition;
>>>>>>> Stashed changes

import javax.sql.DataSource;

public class AccountServiceImpl implements AccountService  {

    private AccountDao accountDao;
    public void setAccountDao(AccountDao accountDao) {
        this.accountDao = accountDao;
    }

<<<<<<< Updated upstream
//    private DataSource dataSource;
//    public void setDataSource(DataSource dataSource) {
//        this.dataSource = dataSource;
//    }
=======
    /*private DataSource dataSource;
    public void setDataSource(DataSource dataSource) {
        this.dataSource = dataSource;
    }*/
>>>>>>> Stashed changes

    public void transfer(String outName, String inName, Double money) {
        //创建事务管理器 开启事务
        /*PlatformTransactionManager pftm = new DataSourceTransactionManager(dataSource);
//      DataSourceTransactionManager dstm = new DataSourceTransactionManager();
//      dstm.setDataSource(dataSource);
        //创建事务定义对象
        TransactionDefinition td = new DefaultTransactionDefinition();
        //创建事务状态对象，用于控制事务执行
        TransactionStatus ts = pftm.getTransaction(td);*/

        accountDao.inMoney(outName,money);
<<<<<<< Updated upstream
        int i = 1/0;
=======
        //int i = 1/0; //模拟业务层事务过程中出现错误
>>>>>>> Stashed changes
        accountDao.outMoney(inName,money);

//        //提交事务
//        pftm.commit(ts);
    }



//    public void transfer(String outName, String inName, Double money) {
//        //开启事务
//        PlatformTransactionManager ptm = new DataSourceTransactionManager(dataSource);
//        //事务定义
//        TransactionDefinition td = new DefaultTransactionDefinition();
//        //事务状态
//        TransactionStatus ts = ptm.getTransaction(td);
//
//        accountDao.inMoney(outName,money);
//        int i = 1/0;
//        accountDao.outMoney(inName,money);
//
//        //提交事务
//        ptm.commit(ts);
//    }

}
